#include "Timer.h"

namespace CEngine
{

#ifdef WINDOWS

#include <windows.h>

I64 Timer::frequency = Timer::getRawFrequency();

Timer::Timer(void)
    :   timerStart(0)
{}

Timer::~Timer(void) {}

void
Timer::startTimer(void) {
    LARGE_INTEGER li;

    QueryPerformanceCounter(&li);

    timerStart = li.QuadPart;
}

D64
Timer::getResolution(void) {
    return (D64)frequency / 1000.0;
}

I64
Timer::getTicks(void) {
    LARGE_INTEGER li;

    QueryPerformanceCounter(&li);

    return li.QuadPart - timerStart;
}

D64
Timer::getTime(void) {
    LARGE_INTEGER li;

    QueryPerformanceCounter(&li);

    return ((D64)(li.QuadPart - timerStart) / (D64)frequency);
}

void
Timer::resetTimer(void) {
    LARGE_INTEGER li;

    QueryPerformanceCounter(&li);

    timerStart = li.QuadPart;
}

I64
Timer::getRawFrequency(void) {
    LARGE_INTEGER li;
    QueryPerformanceFrequency(&li);
    return li.QuadPart;
}

}

#endif
